package demo;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class BlockingQueueDemo {

    //使用阻塞队列组成的模式（生产者-消费者模式）

    private static BlockingQueue<Integer>  blockingQueue=new ArrayBlockingQueue<>(10);
   //阻塞队列容量上限为10，放满会阻塞

    private static class Producer extends Thread {

        @Override
        public void run() {
            int i=0;
            while(true){
                try{
                    blockingQueue.put(i);
                    System.out.println("生产者放入了"+i);
                    i++;
                    //放满后会阻塞
                }catch(InterruptedException ignored){

                }
            }
        }
    }

    public static void main(String[] args) {
        Producer producer=new Producer();
        producer.start();
    }
}
